package team.zero.lemon.module.dictionary.service;

import team.zero.lemon.common.exception.CustomException;
import team.zero.lemon.common.persistence.Page;
import team.zero.lemon.common.service.CrudService;
import team.zero.lemon.module.dictionary.dao.IDictionaryDao;
import team.zero.lemon.module.dictionary.entity.Dictionary;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by bolin on 2016/4/28.
 */
@Service
public class DictionaryService extends CrudService<IDictionaryDao, Dictionary> {
    @Transactional
    public boolean deleteAll() {
        try {
            dao.deleteAll();
            return true;
        } catch (Exception e) {
            throw new CustomException(e.getMessage());
        }
    }
    @Cacheable(value = "dictionaryEhcache")
    public List<Dictionary> findByParentId(Dictionary dic) {
        try {
            return dao.findByParentId(dic);
        } catch (Exception e) {
            throw new CustomException(e);
        }
    }
    @Cacheable(value = "dictionaryEhcache")
    public Dictionary findByParentIdAndName(int prarentId, String name) {
        try {
            return dao.findByParentIdAndName(prarentId, name);
        } catch (Exception e) {
            throw new CustomException(e);
        }
    }
}
